﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using RL;
using System.Web;
using System.Web.Security;
public abstract class PageTemplate : Page
	{
	  public bool IsTestMode
	{
		get
		{
			string querystringWord = WebAppSettings.TestingQuerystringWord;
			if (querystringWord.IsInQuery())
			{
				if (
					querystringWord.FromQuery() == "1"
					|| querystringWord.FromQuery().ToLower() == "true"
					|| querystringWord.FromQuery().ToLower() == "yes"
					|| querystringWord.FromQuery().ToLower() == "y"
					|| querystringWord.FromQuery().ToLower() == "t"
					) return true;
			}
			return false;
		}
	}
		public string Image(string imageName)
		{
			return string.Format("/App_Themes/{0}/images/{1}", this.Theme, imageName);
		}
		public void PreserveUserName(string userName)
		{
				Session["UserName"] = userName;
				HttpCookie userNameCookie = new HttpCookie("UserName");
				userNameCookie.Value = userName;
				Response.Cookies.Add(userNameCookie);
		}
		public string UserName
		{
			get
			{
				if (this.Page.User.Identity.Name.IsNotNullOrEmpty())
					return Page.User.Identity.Name;

				if (Session["UserName"].IsNotNullOrEmpty())
					return Session["UserName"].text();

				HttpCookie userNameCookie = Request.Cookies["UserName"];
				if (userNameCookie.IsNotNull()) return userNameCookie.Value;

				if (WebAppSettings.RedirectIfUserNameExpires && !Request.RawUrl.ToLower().Contains("login.aspx"))
					FormsAuthentication.RedirectToLoginPage();

				return string.Empty;
			}
		}
	}
